package com.wt.admin.service.language.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wt.admin.code.language.SentenceConfig2300;
import com.wt.admin.code.language.Tagging2100;
import com.wt.admin.domain.dto.language.SentenceConfigDTO;
import com.wt.admin.domain.entity.language.SentenceConfigEntity;
import com.wt.admin.domain.entity.sys.SysMenuEntity;
import com.wt.admin.domain.vo.language.SentenceConfigVO;
import com.wt.admin.domain.vo.sys.UserVO;
import com.wt.admin.mapper.language.SentenceConfigMapper;
import com.wt.admin.mapper.sys.SysMenuMapper;
import com.wt.admin.service.language.SentenceConfigService;
import com.wt.admin.util.AssertUtil;
import org.dromara.easyai.config.SentenceConfig;
import org.dromara.easyai.config.TfConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;

@Service
public class SentenceConfigServiceImpl extends ServiceImpl<SentenceConfigMapper, SentenceConfigEntity> implements SentenceConfigService {

    @Resource
    private SentenceConfigMapper sentenceConfigMapper;

    @Override
    public SentenceConfigVO findConfig(SentenceConfigDTO data, UserVO user) {
        SentenceConfigVO sentenceConfigVO = sentenceConfigMapper.selectByTag(data.getTag());
        if(ObjectUtil.isEmpty(sentenceConfigVO)){
            SentenceConfig sentenceConfig = new SentenceConfig();
            sentenceConfigVO = BeanUtil.copyProperties(sentenceConfig, SentenceConfigVO.class);
        }
        sentenceConfigVO.setTag(data.getTag());
        if(ObjectUtil.isEmpty(sentenceConfigVO.getTf())) {
            TfConfig tfConfig = new TfConfig();
            SentenceConfigEntity.TF tf = BeanUtil.copyProperties(tfConfig, SentenceConfigEntity.TF.class);
            tf.setUse(false);
            sentenceConfigVO.setTf(tf);
        }
        return sentenceConfigVO;
    }

    @Transactional
    @Override
    public SentenceConfigVO updateConfig(SentenceConfigDTO data, UserVO user) {
        AssertUtil.Str.isEmpty(data.getTag(), SentenceConfig2300.CODE_2300);
        saveOrUpdate(data);

        return null;
    }

}
